<?php
require('main.php');


class Language extends Main
{
	 function Language()
	 {
		parent::Main();
		$this->database();
		$this->lib('pagination');
		$this->lib('message');	
	 }
	
	function show()
	{
		$this->my_view("manage/language/language",$this->languageList() );
	}
	
	
	

	/**
	 * 
	 * 添加语言。
	 * 
	 */
	function init_add()
	{
		$this->my_view("manage/language/language_add");
		
	}
	
	function add()
	{   
		
	    $result = $this->db->insert("languages",$this->_fetch_form() );
	    
		if( $result ) {
			
			$this->message->set("恭喜你,添加成功！");
			$this->my_view('manage/language/language_success');
		}
		else {
            
            $this->message->set("抱歉添加失败！");
			$this->my_view('manage/language/language_add' );
		}
		
	}
	
	
	
	/**
	 * 
	 * 删除语言。。。
	 * @param $id
	 * @return unknown_type
	 */
	
	function delete()
	{
	    $id_sql = join(",", $_POST['id']);	
		$result = $this->db->delete('languages',"id in($id_sql)");
		
        if( $result ) {
			
			$this->message->set("恭喜你,删除成功！");
			$this->my_view('manage/language/language',$this->languageList() );
		}
		else {
            
            $this->message->set("抱歉,删除失败！");
			$this->my_view('manage/language/language',$this->languageList()  );
		}
		
	}
	
	/**
	 * 
	 * 修改语言内容； 
	 * @param $id
	 * @return unknown_type
	 */
	function init_update($id)
	{
		$language_id_row = $this->db->find("select * from languages where id= $id");
		$data = array(
		'language_id_row'=>$language_id_row
		);
		
		$this->my_view('manage/language/language_update', $data);
		
	}
	function update()
	{
		
		$language_id_row = $this->db->find("select * from languages where id=".$_POST['id']);
		$data = array(
		'language_id_row'=>$language_id_row
		);
		
		
		
		$result = $this->db->update("languages",$this->_fetch_form(),'id='.$_POST['id']);
		
		if($result){
			$this->message->set("恭喜你,修改成功！");
			$this->my_view("manage/language/language",$this->languageList() );
		}
		
		else{
			$this->message->set("抱歉,修改失败！");
			$this->my_view("manage/language/language_update",$data);
		}
		
	}
	/**
	 * 
	 * 语言列表；
	 */
	
	function languageList()
	{
		$total = $this->db->count('languages');
		$config= array(
		'total_row' => $total
		);
		$this->pagination->init($config);
		$language_list = $this->db->find("select * from languages limit "
		                .$this->pagination->start_row.",10");
		return  array(
		'language_list' =>$language_list
		);
		                
		
	}
	
	/**
	 * 
	 * 语言的插入语句；
	 * 
	 * 
	 */
	function _fetch_form()
	{
		return array(
		'name'=>$_POST['name'],
		'code'=>$_POST['code']
		);
		
		
	}
	
	
	
	
	
	

}
?>